﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Zarzadzanie_Restautacja.Model
{
    [Table("ZamowieniaPotrawy", Schema = "dbo")]
    public class ZamowieniaPotrawy
    {
        [Column("ZamId")]
        public int IdZamowienia { get; set; }

        [Column("ID"), DatabaseGenerated(DatabaseGeneratedOption.None), Key]
        public int Id { get; set; }

        [Column("PotId")]
        public int IdPotrawy { get; set; }

        [Column("PotrawaWydana")]
        public int CzyWydana { get; set; }

        [Column("Ilosc")]
        public int Ilosc { get; set; }

        public static int PobierzWolneId(RestauracjaContext context)
        {
            if (context.ZamowieniaPotrawy.Any() && context.ZamowieniaPotrawy.Local.Count == 0)
            {
                return context.ZamowieniaPotrawy.Max(zam => zam.Id) + 1;
            }
            else if (context.ZamowieniaPotrawy.Local.Count > 0)
            {
                return context.ZamowieniaPotrawy.Local.Max(zam => zam.Id) + 1;
            }
            else
            {
                return 0;
            }
        }
    }
}
